package com.hospital.controller;

import com.hospital.domain.DTO.RecordDTO;
import com.hospital.domain.pojo.MedicalRecord;
import com.hospital.domain.utils.Result;
import com.hospital.service.MedicalRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/medical")
@Tag(name = "就诊记录接口", description = "无")
public class MedicalRecordController {

    private final MedicalRecordService medicalRecordService;

    @Operation(summary = "医生提交就诊记录（写病历）")
    @PostMapping("/record")
    public Result record(@RequestBody RecordDTO recordDTO){
        return medicalRecordService.record(recordDTO.getRId(), recordDTO.getResult(), recordDTO.getInfo(), recordDTO.getAdvice());
    }

    @Operation(summary = "查看就诊记录（查病历）")
    @GetMapping("/record/{rId}")
    public Result getRecord(@PathVariable("rId") Integer rId){
        MedicalRecord record = medicalRecordService.lambdaQuery().eq(MedicalRecord::getRId, rId).one();
        return Result.ok(record);
    }

    @Operation(summary = "获取所有病历信息（管理员用）")
    @GetMapping("/record/queryAll")
    public Result queryAllMedicalRecords(){
        return medicalRecordService.queryAllMedicalRecords();
    }

    @Operation(summary = "按医生ID获取病历列表")
    @GetMapping("/record/doctor/{dId}")
    public Result queryMedicalRecordsByDoctor(@PathVariable("dId") Integer dId){
        return medicalRecordService.queryMedicalRecordsByDoctor(dId);
    }
}
